Conversation
Reviewer's GuideThis PR introduces a comprehensive job orchestration framework by defining a jobs/job_steps model in Supabase, implementing secure Edge Functions to manage job lifecycles and aggregate step statuses, integrating n8n workflows for deterministic phase execution, and extending the frontend with realtime subscriptions, toast notifications, and a dedicated JobMonitor component to visualize progress. Sequence diagram for n8n workflow orchestrating job creation and step updates via Edge FunctionssequenceDiagram
actor User
participant Frontend
participant n8n
participant EdgeFunctions
participant SupabaseDB
User->>Frontend: Initiates resource processing
Frontend->>n8n: Triggers workflow (webhook)
n8n->>EdgeFunctions: POST /create-job (with steps)
EdgeFunctions->>SupabaseDB: Insert job and job_steps
EdgeFunctions-->>n8n: Job created response
n8n->>EdgeFunctions: POST /update-job-step (step status)
EdgeFunctions->>SupabaseDB: Update job_steps, aggregate job status
EdgeFunctions-->>n8n: Step update response
n8n->>EdgeFunctions: Repeat for each step (branching as needed)
EdgeFunctions->>SupabaseDB: Finalize job when all steps terminal
SupabaseDB-->>Frontend: Emit realtime change events
Frontend->>User: Show progress toasts and JobMonitor updates
Entity relationship diagram for jobs and job_steps tableserDiagram
JOBS {
string id PK
string user_id
string workflow_name
string workflow_execution_id
string status
string created_at
string started_at
string completed_at
string error_message
json metadata
int resource_id
}
JOB_STEPS {
string id PK
string job_id FK
string step_name
string step_type
string status
string started_at
string completed_at
string error_message
json output_data
int step_order
json metadata
}
JOBS ||--o{ JOB_STEPS : has
Class diagram for Job, JobStep, JobWithSteps, and JobNotification typesclassDiagram
class Job {
string id
string user_id
string workflow_name
string workflow_execution_id
JobStatus status
string created_at
string started_at
string completed_at
string error_message
json metadata
int resource_id
}
class JobStep {
string id
string job_id
string step_name
string step_type
JobStepStatus status
string started_at
string completed_at
string error_message
json output_data
int step_order
json metadata
}
class JobWithSteps {
JobStep[] steps
}
class JobNotification {
string type
Job job
JobStep step
string message
}
JobWithSteps --|> Job
JobWithSteps "1" o-- "many" JobStep
JobNotification --> Job
JobNotification --> JobStep
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/get-job-status' \ | ||
| --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ |
There was a problem hiding this comment.
security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.
Source: gitleaks
| 2. Make an HTTP request: | ||
|
|
||
| curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/get-job-status' \ | ||
| --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ |
There was a problem hiding this comment.
security (jwt): Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
Source: gitleaks
| curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/update-job-step' \ | ||
| --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ |
There was a problem hiding this comment.
security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.
Source: gitleaks
| 2. Make an HTTP request: | ||
|
|
||
| curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/update-job-step' \ | ||
| --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ |
There was a problem hiding this comment.
security (jwt): Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
Source: gitleaks
…steps toasts' content text
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a comprehensive job orchestration system that enables end-to-end workflow tracking for resource processing. The implementation provides real-time progress notifications, integrates with n8n workflows, and establishes a robust backend infrastructure for managing multi-step processing pipelines.
Key changes include:
- Added job and job_steps database tables with corresponding Supabase Edge Functions for lifecycle management
- Implemented real-time UI notifications system with progress tracking and toast notifications
- Created n8n workflow integration with proper error handling and execution correlation
Reviewed Changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| supabase/functions/create-job/index.ts | New Edge Function for job creation with user authentication and step initialization |
| supabase/functions/update-job-step/index.ts | New Edge Function for step status updates with automatic job status aggregation |
| supabase/functions/get-job-status/index.ts | New Edge Function for retrieving job status and progress information |
| frontend/src/hooks/use-job-notifications.tsx | Real-time subscription hook for job and step notifications with toast integration |
| frontend/src/components/job-monitor.tsx | UI component for displaying job status and progress with Italian localization |
| frontend/src/services/jobService.ts | Service layer for job-related API calls and data management |
| frontend/src/types/job.ts | TypeScript type definitions for job entities and related interfaces |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const nowIso = new Date().toISOString() | ||
| updateData.completed_at = nowIso | ||
| // If step jumped directly from pending -> terminal without a running phase, also set started_at | ||
| updateData.started_at = updateData.started_at || nowIso |
There was a problem hiding this comment.
This line attempts to set started_at on updateData, but updateData.started_at is not defined at this point, so the fallback will always execute. Consider checking if the step already has a started_at value from the database instead.
| updateData.started_at = updateData.started_at || nowIso | |
| updateData.started_at = currentStep?.started_at || nowIso |
| const limit = parseInt(url.searchParams.get('limit') || '10') | ||
| const status = url.searchParams.get('status') | ||
|
|
||
| if (jobId) { |
There was a problem hiding this comment.
This assignment is unnecessary since jobIdParam could be used directly in the conditional check below.
| if (jobId) { | |
| const limit = parseInt(url.searchParams.get('limit') || '10') | |
| const status = url.searchParams.get('status') | |
| if (jobIdParam) { |
| Authorization: `Bearer ${session.access_token}`, | ||
| } | ||
| }); | ||
|
|
There was a problem hiding this comment.
The function name should not include query parameters. Query parameters should be passed separately or the URL should be constructed properly using the base function name.
| // Pass jobId as a custom header instead of query parameter | |
| const { data, error } = await supabase.functions.invoke('get-job-status', { | |
| method: 'GET', | |
| headers: { | |
| Authorization: `Bearer ${session.access_token}`, | |
| 'x-job-id': jobId, | |
| } | |
| }); | |
| <DropdownMenuContent> | ||
| <DropdownMenuItem onClick={() => onCancel(job.id)}> | ||
| Annulla Workflow | ||
| </DropdownMenuItem> |
There was a problem hiding this comment.
[nitpick] Mixed language usage - Italian text 'Annulla Workflow' in a component that has other English text. Consider using consistent localization throughout the component.
| </DropdownMenuItem> | |
| <DropdownMenuItem onClick={() => onCancel(job.id)}> | |
| Cancel Workflow | |
| </DropdownMenuItem> |
…rting newest/oldest to use processed_at timestampt instead of created_at timestamp; use-job-notifications realtime subscription configuration not properly working; add-resource form input placeholder changed to 'Resource Link'; failed workflow toast (destructive) is now the last toast that appears impeding failed steps toasts to display; create-job supabase function to fetch user email using userList as getUserByEmail is not supported. feat: added --success color and toast variant and utilized it for successful workflow toast.
…s fallback; minor UI issues for mobile screens; handling of svg icons, they now have their own component file
…on in public/ for SMTP server email sender
…ions to handle already available records from database
feat: end-to-end job orchestration, realtime workflow tracking & n8n integration
High-level
multi-phase resource processing (duplicates check → content type detection →
content extraction → AI processing → database save).
automatic status aggregation (pending → running → completed/failed) and
timestamp management.
including error handler path, branch-specific step outputs and execution ID
correlation.
toasts and English localization; removed duplicate local job creation.
request/response schema, headers and metadata fields.
Database & Realtime
metadata) and job_steps (per-step status, output_data/metadata, ordering).
change events used by frontend toasts.
terminal; direct skip to terminal sets started_at defensively.
Edge Functions
(existing resource CRUD adapted to cooperate with job pipeline).
guards against partial step waves.
Frontend
useJobNotificationshook subscribing to jobs + job_steps realtimechannels; progress computation (completed/skipped vs total) with percentage.
hint) / workflow completed / workflow failed (destructive).
n8n Workflow
initial steps definition for deterministic ordering.
step_name set to one semantic step per phase; avoided name collisions in
same branch.
extraction lengths, AI model info, tags/key points counts, saved resource id.
by migrating bodies toward expression-object style or corrected raw JSON.
guarded when job_id is missing.
Notifications & UX
” enabling real-time mental model of pipeline.
Security & Robustness
filtering plus realtime channel filters.
Use Cases (illustrative)
content extraction (transcript), AI processing (LLM summary), database save.
emits “Workflow Completed”.
continue based on config; UI still shows precise failure or skip outcome.
toast “Workflow Failed” with truncated root cause.
Developer Improvements
metrics for later analytics (model usage, content lengths, detection types).
Follow-ups (not included)
or scraping errors.
Summary by Sourcery
Add end-to-end job orchestration with granular job steps, backed by new Supabase tables and edge functions, integrated into n8n workflows, and surfaced in the UI via real-time notifications and a JobMonitor component.
New Features:
Enhancements:
Build:
Documentation: